package com.test.spring.thread;

import java.util.HashMap;
import java.util.concurrent.TimeUnit;

public class ThreadLocalTest1 {
    static final InheritableThreadLocal<HashMap> threadParam = new InheritableThreadLocal<HashMap>();
    public static void main(String[] args) throws InterruptedException {
        HashMap hashMap = new HashMap();
        threadParam.set(hashMap);
        while (true) {
            TimeUnit.SECONDS.sleep(2);
            new Thread(() -> {
                hashMap.put("3", Thread.currentThread().getId());
                threadParam.set(hashMap);
                System.out.println(Thread.currentThread().getId() + ":parent:" + threadParam.get().hashCode() + "==" + threadParam.get());

                new Thread(() -> {
                    hashMap.put("3", Thread.currentThread().getId());
                    threadParam.set(hashMap);
                    System.out.println(Thread.currentThread().getId() + "" +":child:" + threadParam.get().hashCode() + "==" + threadParam.get());
                }).start();

                new Thread(() -> {
                    System.out.println(Thread.currentThread().getId()  + "" +"child:" + threadParam.get().hashCode() + "==" + threadParam.get());
                }).start();
            }).start();
            System.out.println("============");
        }
    }

}
